package org.esir.feature_login.login

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.EditText
import android.widget.ProgressBar
import androidx.annotation.NonNull
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProviders
import org.esir.feature_login.R
import org.esir.login.ui.login.LoginViewModel
import org.esir.login.ui.login.LoginViewModelFactory

/**
 * @ClassName: LoginFragment
 * @Description: (登录交互)
 * @author: huangrongcai
 * @date: 2022/12/4
 *
 */
class LoginFragment : Fragment() {

    private lateinit var loginViewModel: LoginViewModel
    /**
     * #实例化
     */
    @NonNull
    fun newInstance(): LoginFragment {
        return LoginFragment()
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return super.onCreateView(inflater, container, savedInstanceState)

    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        val username = view.findViewById<EditText>(R.id.username)
        val password = view.findViewById<EditText>(R.id.password)
        val login = view.findViewById<Button>(R.id.login)
        val loading = view.findViewById<ProgressBar>(R.id.loading)

        loginViewModel = ViewModelProviders.of(this, LoginViewModelFactory())
                .get(LoginViewModel::class.java)

    }

    /**
     * # 异步请求
     * 请求登录
     */
    fun requestLogin() {}

    /**
     * #事件回调
     */
    fun setOnLoginListener(){}

    private fun login(username: String, password: String) {
        loginViewModel.login(username, password)
    }

    private fun showOnLoginFailed(){}

    private fun showOnLogin(){}
}